package com.itheima.service.impl.store;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.itheima.domain.store.Member;
import com.itheima.domain.store.Orders;
import com.itheima.domain.store.Product;
import com.itheima.mapper.store.OrdersMapper;
import com.itheima.service.store.OrdersService;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrdersServiceImpl implements OrdersService {
    @Override
    //遍历
    public List<Orders> list(int pageNum, int pageSize) {
        SqlSession session = MapperUtil.getSession();
        OrdersMapper mapper = session.getMapper(OrdersMapper.class);
        PageHelper.startPage(pageNum, pageSize);
        List<Orders> list= mapper.findAll();
        return list;
    }

    @Override
    //id查找
    public Orders findById(String id) {
        SqlSession session = MapperUtil.getSession();
        OrdersMapper mapper = session.getMapper(OrdersMapper.class);
        Orders orders=mapper.findById(id);
        session.commit();
        MapperUtil.close(session);
        return orders;
    }

    @Override
    //删除
    public void deleteById(String s) {
        SqlSession session = MapperUtil.getSession();
        OrdersMapper ordersMapper = session.getMapper(OrdersMapper.class);
        //删除order_traveller表中对应的数据
        ordersMapper.deleteOtByOid(s);
        session.commit();
        //删除traveller表中对应的数据
        ordersMapper.deleteTraByOid(s);
        session.commit();
        //删除orders
        ordersMapper.deleteOrdersByOid(s);
        session.commit();
        MapperUtil.close(session);
    }

    @Override
    //模糊查询
    public List<Orders> findByLike(String lms,int pageNum, int pageSize) {
        SqlSession session = MapperUtil.getSession();
        OrdersMapper mapper = session.getMapper(OrdersMapper.class);
        PageHelper.startPage(pageNum,pageSize);
        List<Orders> list= mapper.findAllLike(lms);
        return list;
    }

}
